<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [
    <!ENTITY nbsp "&#xA0;">
    <!ENTITY nl "&#xD;&#xA;">
]>

<!-- stylesheet for common items of mimetype "application/vnd.oasis.opendocument.text" and "application/vnd.oasis.opendocument.spreadsheet" -->

<!-- Version and namespaces -->
<xsl:stylesheet version="1.0"
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:anim="urn:oasis:names:tc:opendocument:xmlns:animation:1.0"
    xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0"
    xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"
    xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
    xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
    xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0"
    xmlns:int="http://opendocumentfellowship.org/internal"
    xmlns:math="http://www.w3.org/1998/Math/MathML"
    xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0"
    xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"
    xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
    xmlns:ooo="http://openoffice.org/2004/office"
    xmlns:oooc="http://openoffice.org/2004/calc"
    xmlns:ooow="http://openoffice.org/2004/writer"
    xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0"
    xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0"
    xmlns:smil="urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0"
    xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
    xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
    xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
    xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
    xmlns:xforms="http://www.w3.org/2002/xforms"
    xmlns:xlink="http://www.w3.org/1999/xlink"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    exclude-result-prefixes="anim chart config dc dr3d draw fo form int math meta number
        office ooo oooc ooow presentation script smil style svg table text xforms xlink #default">

<!-- - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = -->

<!-- GRAPHIC CONTENT - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->

    <!-- add the drawing element's properties in the inline CSS for this object -->
    <xsl:template match="draw:frame/draw:image | draw:frame/draw:text-box" mode="attribs">
        <xsl:if test="../@svg:width">width: <xsl:value-of select="../@svg:width" />; </xsl:if>
        <xsl:if test="../@svg:height">height: <xsl:value-of select="../@svg:height" />; </xsl:if>
        <xsl:if test="../@svg:x">position: relative; left: <xsl:value-of select="../@svg:x" />; </xsl:if>
        <xsl:if test="../@svg:y">top: <xsl:value-of select="../@svg:y" />; </xsl:if>
        <xsl:if test="../@fo:min-width">min-width: <xsl:value-of select="../@fo:min-width" />; </xsl:if>
        <xsl:if test="../@fo:min-height">min-height: <xsl:value-of select="../@fo:min-height" />; </xsl:if>
        <xsl:if test="../@fo:max-width">max-width: <xsl:value-of select="../@fo:max-width" />; </xsl:if>
        <xsl:if test="../@fo:max-height">max-height: <xsl:value-of select="../@fo:max-height" />; </xsl:if>
        <xsl:if test="../@draw:z-index">z-index: <xsl:value-of select="../@draw:z-index" />; </xsl:if>
    </xsl:template>

    <!-- IMAGES - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->

    <!-- template for displaying images: first check where the image is anchored -->
    <xsl:template match="draw:frame/draw:image">
        <xsl:choose>
            <xsl:when test="../@text:anchor-type='as-char'">
                <xsl:apply-templates select="." mode="drawing" />
            </xsl:when>
            <xsl:when test="../@text:anchor-type='char'">
                <xsl:element name="span">
                    <xsl:attribute name="class">
                        <xsl:call-template name="classInheritance">
                            <xsl:with-param name="styleName">
                                <xsl:if test="../@draw:style-name"><xsl:value-of select="../@draw:style-name" /></xsl:if>
                            </xsl:with-param>
                            <xsl:with-param name="class">
                                <xsl:if test="../@draw:style-name"><xsl:value-of select="translate(../@draw:style-name,'.','_')" /></xsl:if>
                            </xsl:with-param>
                            <xsl:with-param name="separator"><xsl:text> </xsl:text></xsl:with-param>
                        </xsl:call-template>
                    </xsl:attribute>
                    <xsl:attribute name="style">
                        <xsl:apply-templates select="." mode="attribs" />
                    </xsl:attribute>
                <xsl:apply-templates select="." mode="drawing" />
                <xsl:apply-templates />
                </xsl:element><xsl:text>&nl;</xsl:text>
            </xsl:when>
            <xsl:otherwise>
                <xsl:element name="div">
                    <xsl:attribute name="class">
                        <xsl:call-template name="classInheritance">
                            <xsl:with-param name="styleName">
                                <xsl:if test="../@draw:style-name"><xsl:value-of select="../@draw:style-name" /></xsl:if>
                            </xsl:with-param>
                            <xsl:with-param name="class">
                                <xsl:if test="../@draw:style-name"><xsl:value-of select="translate(../@draw:style-name,'.','_')" /></xsl:if>
                            </xsl:with-param>
                            <xsl:with-param name="separator"><xsl:text> </xsl:text></xsl:with-param>
                        </xsl:call-template>
                    </xsl:attribute>
                    <xsl:attribute name="style">
                        <xsl:apply-templates select="." mode="attribs" />
                    </xsl:attribute>
                <xsl:apply-templates select="." mode="drawing" />
                <xsl:apply-templates />
                </xsl:element><xsl:text>&nl;</xsl:text>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

    <!-- template for displaying the actual image -->
    <xsl:template match="draw:frame/draw:image" mode="drawing">
        <xsl:element name="img">
            <xsl:attribute name="class">
                <xsl:value-of select="translate(../@draw:style-name,'.','_')" />
            </xsl:attribute>
            <xsl:attribute name="style">
                <xsl:if test="../@svg:width">width: <xsl:value-of select="../@svg:width" />; </xsl:if>
                <xsl:if test="../@svg:height">height: <xsl:value-of select="../@svg:height" />; </xsl:if>
            </xsl:attribute>
            <xsl:if test="../svg:desc"><xsl:attribute name="alt">
                <xsl:value-of select="../svg:desc" />
            </xsl:attribute></xsl:if>
            <xsl:attribute name="src">
              <xsl:value-of select="concat($param_imgloc, @xlink:href)" />
            </xsl:attribute>
        </xsl:element>
    </xsl:template>

    <xsl:template match="svg:desc" />

    <!-- TEXT BOXES - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->

    <xsl:template match="draw:frame/draw:text-box">
        <xsl:element name="div">
            <xsl:attribute name="class">
                <xsl:call-template name="classInheritance">
                    <xsl:with-param name="styleName">
                        <xsl:if test="../@draw:style-name"><xsl:value-of select="../@draw:style-name" /></xsl:if>
                    </xsl:with-param>
                    <xsl:with-param name="class">
                        <xsl:if test="../@draw:style-name"><xsl:value-of select="translate(../@draw:style-name,'.','_')" /></xsl:if>
                    </xsl:with-param>
                    <xsl:with-param name="separator"><xsl:text> </xsl:text></xsl:with-param>
                </xsl:call-template>
            </xsl:attribute>
            <xsl:attribute name="style">
                <xsl:apply-templates select="." mode="attribs" />
                <xsl:if test="../@draw:z-index">z-index: <xsl:value-of select="../@draw:z-index" />; </xsl:if>
            </xsl:attribute>
            <xsl:apply-templates />
        </xsl:element><xsl:text>&nl;</xsl:text>
    </xsl:template>

    <!-- SHAPES: Rectangle - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
    <xsl:template match="draw:rect">
        <xsl:element name="div">
            <xsl:attribute name="class">
                <xsl:if test="@draw:style-name">
                    <xsl:call-template name="callClassInheritance">
                        <xsl:with-param name="paramValue"><xsl:value-of select="@draw:style-name" /></xsl:with-param>
                    </xsl:call-template>
                </xsl:if>
                <xsl:if test="@draw:text-style-name">
                    <xsl:text> </xsl:text><xsl:value-of select="@draw:text-style-name" />
                </xsl:if>
            </xsl:attribute>
            <xsl:attribute name="style">
                <xsl:apply-templates select="." mode="attribs" />
            </xsl:attribute>
        <xsl:apply-templates />
        </xsl:element>
    </xsl:template>

    <!-- add the drawing element's properties in the inline CSS for this object -->
    <xsl:template match="draw:rect" mode="attribs">
        <xsl:if test="@svg:width">width: <xsl:value-of select="@svg:width" />; </xsl:if>
        <xsl:if test="@svg:height">height: <xsl:value-of select="@svg:height" />; </xsl:if>
        <xsl:if test="@draw:z-index">z-index: <xsl:value-of select="@draw:z-index" />; </xsl:if>
    </xsl:template>

<!-- - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = -->

    <xsl:template match="number:number-style|number:number|number:scientific-number|number:fraction|
            number:currency-style|number:currency-symbol|number:text|style:map">
        <!-- do nothing for now for items we cannot interpret -->
    </xsl:template>

</xsl:stylesheet>
